<?php
/**
* Admin Sips Controller
*
* This handles all AJAX requests from the Admin GUI Sips Configuration page.
* These methods will create an AJAX response containing JSON data. The JSON
* data is read by the JS code and rendered into interface.
*
* @access 	public
* @author 	Rob, Valentin
* @copyright	ResMania 2009 all rights reserved.
* @version	1.0
* @link		http://developer.resmania.com/api
* @since  	05-2009
*/
class RM_Admin_SipsController extends RM_Controller
{
    /**
     * This loads the Authorize.net configuration, the data is retrieved using the
     * RM_SipsConfig class
     *
     * @return 	json    json array information containing Authorize.net information
     */
    public function configJsonAction(){

        $sipsObj = new RM_SipsConfig;
        $settings = $sipsObj->getSettings()->toArray();

        $json = new stdClass;
        $json->settings = $settings;

        return array(
            'data' => $json
        );
    }

    /**
     * This saves the sips settings from the plugin->sips setting page
     *
     * @return 	json    success value true/false
     */
    public function updateJsonAction(){

        $id = $this->_getParam('id');
        $sipsObj = new RM_SipsConfig;

        // find the current record from the DB
        $details = $sipsObj->find($id)->current();

        $status = true;

        if (!$details) {
            $status = 'false';
        } else {
            $details->id = $id;
            $details->merchant_id = $this->_getParam('merchant_id');
            $details->parcom = $this->_getParam('parcom');
            $details->cgibin_path = $this->_getParam('cgibin_path');
            $details->verified_status = $this->_getParam('verified_status');
            $details->invalid_status = $this->_getParam('invalid_status');
            $details->version = $this->_getParam('version');
            $details->currency_id = $this->_getParam('currency_id');
            $details->country = $this->_getParam('country');
            $details->payment_means = $this->_getParam('payment_means');
            $details->header_flag = $this->_getParam('header_flag');
            $details->capture_mode = $this->_getParam('capture_mode');
            $details->capture_day = $this->_getParam('capture_day');
            $result = $details->save();

            if ($result!='1') $status = 'false';
        }
        return array(
            'data' => array('success' => $status)
        );

    }
}